/**
 * Copyright (C) 2011-2012 GreenSoft S.A.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ar.com.greensoft.neosystem.model.address;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import ar.com.greensoft.neosystem.model.NamedEntity;
import ar.com.greensoft.neosystem.model.references.ISO3166_1;

/**
 * 
 * @author Jorge E. Villaverde
 * @since 24/01/2012
 * @version 1.0.0
 */
@Entity
@Table(name="pais")
@Cacheable(value=false)
@Inheritance(strategy=InheritanceType.JOINED)
@NamedQueries({
	@NamedQuery(name=Pais.FIND_ALL_QUERY_NAME, query="SELECT p FROM Pais p ORDER BY p.name"),
	@NamedQuery(name=Pais.FIND_LIKE_NAME_QUERY_NAME, query="SELECT p FROM Pais p WHERE p.name LIKE :name"),
	@NamedQuery(name=Pais.FIND_BY_NAME_QUERY_NAME, query="SELECT p FROM Pais p WHERE p.name = :name"),
	@NamedQuery(name=Pais.FIND_BY_ISO_QUERY_NAME, query="SELECT p FROM Pais p WHERE p.codigoISO = :codigoISO"),
	@NamedQuery(name=Pais.COUNT_QUERY_NAME,    query="SELECT COUNT(p) FROM Pais p")
})
public class Pais extends NamedEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static final String FIND_LIKE_NAME_QUERY_NAME = "Pais.findNameLike";
	public static final String FIND_ALL_QUERY_NAME = "Pais.findAll";
	public static final String FIND_BY_NAME_QUERY_NAME = "Pais.findByName";
	public static final String FIND_BY_ISO_QUERY_NAME = "Pais.findByISO";
	public static final String COUNT_QUERY_NAME = "Pais.count";

	/**
	 * C&oacute;digo ISO de los Paises
	 */
	@Enumerated(EnumType.STRING)
	@Column(name = "CODIGOISO")
	private ISO3166_1 codigoISO;
	
    @OneToMany(mappedBy = "pais", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
    private List<Provincia> provincias = Collections.synchronizedList(new ArrayList<Provincia>()); 	

	public ISO3166_1 getCodigoISO() {
		return codigoISO;
	}

	public void setCodigoISO(ISO3166_1 codigoISO) {
		this.codigoISO = codigoISO;
	}

	public List<Provincia> getProvincias() {
		return provincias;
	}

	public void setProvincias(List<Provincia> provincias) {
		this.provincias = provincias;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((codigoISO == null) ? 0 : codigoISO.hashCode());
		result = prime * result
				+ ((provincias == null) ? 0 : provincias.hashCode());
		return result;
	}	
}
